<template>
  <div
      :class="['download_layer', {'download_layer_show': isShow}]"
      @mouseenter="downLayerType(true)"
      @mouseleave="downLayerType(false)"
  >
    <div>
      <ul>
        <li
            v-for="(v,i) in downloadChannel"
            :key="i"
            ref="downloadLi"
            :class="['download_li',{'li_active': i === btnHoverIndex}]"
            @mouseenter="btnHoverIndex = i"
        >
          <div v-if="v.id === 'ios'" ref="downloadIcon"
               :class="['icon', 'icon_ios', {'icon_ios_active': btnHoverIndex === i}]"></div>
          <div v-else-if="v.id === 'android'" ref="downloadIcon"
               :class="['icon', 'icon_android', {'icon_android_active': btnHoverIndex === i}]"></div>
          <div v-else-if="v.id === 'weChat'" ref="downloadIcon"
               :class="['icon', 'icon_wechat', {'icon_wechat_active': btnHoverIndex === i}]"></div>
          <span>{{ v.name }}</span>
        </li>
      </ul>
      <div class="right_img">
        <img
            :src="codeImageSrc"
            alt=""
            class="right_img_info"
        />
        <span ref="description" class="right_description">扫一扫下载IOS客户端</span>
      </div>
    </div>
  </div>
</template>

<script>
import {downloadChannel} from "@/utils/downloadChannel";

const iosCode = require("@/assets/img/code_img_android.png")
const androidCode = require("@/assets/img/code_img_android.png")
const weChatCode = require("@/assets/img/code_img_ios.jpg")
export default {
  name: "BaseDownloadLayer",
  data() {
    return {
      isShow: false,
      downloadChannel,
      activeArr: ["icon_ios_active", "icon_android_active", "icon_wechat_active"],
      codeImageSrc: iosCode,
      btnHoverIndex: 0,
    }
  },
  mounted() {
    this.$EventBus.$on("downloadLayerVisible", bool => {
      this.isShow = bool
    })
  },
  watch: {
    btnHoverIndex(nVal) {
      this.$refs.description.innerHTML = downloadChannel[nVal].title
      if (nVal === 0) {
        this.codeImageSrc = iosCode
      } else if (nVal === 1) {
        this.codeImageSrc = androidCode
      } else if (nVal === 2) {
        this.codeImageSrc = weChatCode
      }
    }
  },
  methods: {
    downLayerType(bool) {
      this.isShow = bool
    },
  }
}
</script>

<style lang="scss" scoped>
.download_layer {
  position: fixed;
  right: 1vw;
  top: 50px;
  width: 360px;
  background-color: #FFFFFF;
  border-radius: 5px;
  height: 240px;
  display: none;
  z-index: 999;
  border: 1px solid #eee7e7;

  > div {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    border-radius: 5px;

    > ul {
      flex: .4;
      height: 100%;
      background-color: #F5F5F5;
      border-radius: 5px 0 0 5px;

      .download_li {
        height: 50px;
        display: flex;
        padding-left: 14px;
        align-items: center;
        cursor: pointer;
        font-size: 14px;
        position: relative;

        .icon {
          width: 20px;
          height: 20px;
          background-size: contain;
          background-position: center;
          background-repeat: no-repeat;
          margin-right: 10px;
        }

        .icon_ios {
          background-image: url("@/assets/img/ios.png");
        }

        .icon_android {
          background-image: url("@/assets/img/android.png");
        }

        .icon_wechat {
          background-image: url("@/assets/img/wechat_mini.png");
        }

        .icon_ios_active {
          background-image: url("@/assets/img/ios_active.png");
        }

        .icon_android_active {
          background-image: url("@/assets/img/android_active.png");
        }

        .icon_wechat_active {
          background-image: url("@/assets/img/wechat_mini_active.png");
        }
      }

      .li_active:before {
        content: "";
        height: 60%;
        display: block;
        position: absolute;
        border: 1px solid #EA0014;
        left: 0;
      }

      .li_active {
        background-color: #FFFFFF;
      }
    }

    .right_img {
      flex: .6;
      height: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border-radius: 0 5px 5px 0;

      .right_img_info {
        width: 172px;
        height: auto;
      }
    }

    > div > span {
      font-size: 14px;
    }
  }
}

.download_layer_show {
  display: block;
}
</style>